package com.cfuture08.eweb4j.jdbc.sql;

import com.cfuture08.eweb4j.cache.ORMConfigBeanCache;
import com.cfuture08.eweb4j.cache.SingleBeanCache;
import com.cfuture08.eweb4j.orm.config.bean.ORMConfigBean;
import com.cfuture08.eweb4j.orm.config.bean.Property;
import com.cfuture08.eweb4j.orm.dao.config.bean.DAOConfigBean;
import com.cfuture08.util.ReflectUtil;
import com.cfuture08.util.StringUtil;

/**
 * 创建查询的SQL语句
 * 
 * @author cfuture.aw
 * @since v1.a.0
 * @param <T>
 */
public class SelectSqlCreator<T> {
	private T t;

	public SelectSqlCreator(T t) {
		this.t = t;
	}

	public String select(String condition) {
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean != null ? ormBean.getTable() : t.getClass()
				.getSimpleName();
		return String.format("SELECT * FROM %s WHERE %s ;", table, condition);
	}

	/**
	 * 各种条件查询
	 * 
	 * @param columns
	 *            构成条件的字段名数组
	 * @param values
	 *            构成条件的字段值
	 * @param likeType
	 *            匹配类型 -1左匹配 0全匹配 1右匹配
	 * @param isLike
	 *            是否模糊查询
	 * @param orderColumn
	 *            对哪个字段进行排序
	 * @param oType
	 *            升序还是降序
	 * @return 字符串
	 * @param currentPage
	 *            第几页
	 * @param numPerPage
	 *            每页显示多少条
	 * @return
	 * @throws Exception
	 */
	public String selectWhere(String[] columns, String[] values, int likeType,
			boolean isLike, boolean isNot, String orderColumn, int oType,
			int currentPage, int numPerPage) throws Exception {
		String[] type = null;
		String orderType = OrderType.ASC_ORDER == oType ? "ASC" : "DESC";
		if (isLike) {
			if (LikeType.LEFT_LIKE == likeType) {
				if (isNot) {
					type = new String[] { " NOT LIKE ", " OR ", " '", "%' " };
				} else {
					type = new String[] { " LIKE ", " OR ", " '", "%' " };
				}
			} else if (LikeType.RIGHT_LIKE == likeType) {
				if (isNot) {
					type = new String[] { " NOT LIKE ", " OR ", " '%", "' " };
				} else {
					type = new String[] { " LIKE ", " OR ", " '%", "' " };
				}
			} else if (LikeType.ALL_LIKE == likeType) {
				if (isNot) {
					type = new String[] { " NOT LIKE ", " OR ", " '%", "%' " };
				} else {
					type = new String[] { " LIKE ", " OR ", " '%", "%' " };
				}
			}
		} else {
			if (isNot) {
				type = new String[] { " <> ", " AND ", " '", "' " };
			} else {
				type = new String[] { " = ", " AND ", " '", "' " };
			}

		}
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		if (ormBean == null) {
			if (orderColumn == null) {
				orderColumn = "id";
			}
		} else {
			if (orderColumn == null) {
				for (Property p : ormBean.getProperty()) {
					if (("true".equals(p.getPk()) || "1".equals(p.getPk()))
							&& ("true".equals(p.getAutoIncrement()) || "1"
									.equals(p.getAutoIncrement()))) {
						orderColumn = p.getColumn();
						break;
					}
				}
			}
		}

		StringBuilder condition = new StringBuilder();

		for (int i = 0; i < columns.length; ++i) {
			if (values != null) {
				if (condition.length() > 0) {
					condition.append(type[1]).append(columns[i]).append(" ")
							.append(type[0]).append(type[2]).append(values[i])
							.append(type[3]);
				} else {
					condition.append(columns[i]).append(" ").append(type[0])
							.append(type[2]).append(values[i]).append(type[3]);
				}
			} else {
				ReflectUtil ru = new ReflectUtil(t);
				if (ormBean == null) {
					for (String name : ru.getFieldsName()) {
						if (columns[i].equals(name)) {
							Object value = ru.getMethod(
									"get" + StringUtil.toUpCaseFirst(name))
									.invoke(t);
							if (condition.length() > 0) {

								condition.append(type[1]).append(columns[i])
										.append(" ").append(type[0]).append(
												type[2]).append(value).append(
												type[3]);
							} else {
								condition.append(columns[i]).append(" ")
										.append(type[0]).append(type[2])
										.append(value).append(type[3]);
							}
						}
					}
				} else {
					for (Property p : ormBean.getProperty()) {
						if (columns[i].equals(p.getColumn())) {
							Object value = ru.getMethod(
									"get"
											+ StringUtil.toUpCaseFirst(p
													.getName())).invoke(t);
							if (condition.length() > 0) {

								condition.append(type[1]).append(columns[i])
										.append(" ").append(type[0]).append(
												type[2]).append(value).append(
												type[3]);
							} else {
								condition.append(columns[i]).append(" ")
										.append(type[0]).append(type[2])
										.append(value).append(type[3]);
							}
						}
					}
				}

			}
		}
		if (currentPage > 0 && numPerPage > 0) {
			return String.format(
					"SELECT * FROM %s WHERE %s ORDER BY %s %s LIMIT %s, %s;",
					table, condition.toString(), orderColumn, orderType, String
							.valueOf((currentPage - 1) * numPerPage), String
							.valueOf(currentPage * numPerPage));
		} else {
			return String.format("SELECT * FROM %s WHERE %s ORDER BY %s %s ;",
					table, condition.toString(), orderColumn, orderType);
		}
	}

	public String selectWhere(String[] columns, String[] values, int likeType,
			boolean isLike, String orderColumn, int oType, int currentPage,
			int numPerPage) throws Exception {
		return this.selectWhere(columns, values, likeType, isLike, false,
				orderColumn, oType, currentPage, numPerPage);
	}

	public String selectWhere(String[] columns, String[] values,
			String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, values, 0, false, false, orderColumn,
				orderType, -1, -1);
	}

	public String selectWhereNot(String[] columns, String[] values,
			String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, values, 0, false, true, orderColumn,
				orderType, -1, -1);
	}

	public String selectWhere(String[] columns, String[] values,
			String orderColumn, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, values, 0, false, false, orderColumn,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, String[] values,
			String orderColumn, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, values, 0, false, true, orderColumn,
				orderType, currentPage, numPerPage);
	}

	public String selectWhere(String[] columns, String orderColumn,
			int orderType) throws Exception {
		return this.selectWhere(columns, null, 0, false, false, orderColumn,
				orderType, -1, -1);
	}

	public String selectWhereNot(String[] columns, String orderColumn,
			int orderType) throws Exception {
		return this.selectWhere(columns, null, 0, false, true, orderColumn,
				orderType, -1, -1);
	}

	public String selectWhere(String[] columns, String orderColumn,
			int orderType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, 0, false, false, orderColumn,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, String orderColumn,
			int orderType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, 0, false, true, orderColumn,
				orderType, currentPage, numPerPage);
	}

	public String selectWhere(String[] columns, String[] values, int orderType)
			throws Exception {
		return this.selectWhere(columns, values, 0, false, false, null,
				orderType, -1, -1);
	}

	public String selectWhereNot(String[] columns, String[] values,
			int orderType) throws Exception {
		return this.selectWhere(columns, values, 0, false, true, null,
				orderType, -1, -1);
	}

	public String selectWhere(String[] columns, String[] values, int orderType,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, 0, false, false, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, String[] values,
			int orderType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, 0, false, true, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhere(String[] columns, int orderType) throws Exception {
		return this.selectWhere(columns, null, 0, false, false, null,
				orderType, -1, -1);
	}

	public String selectWhereNot(String[] columns, int orderType)
			throws Exception {
		return this.selectWhere(columns, null, 0, false, true, null, orderType,
				-1, -1);
	}

	public String selectWhere(String[] columns, int orderType, int currentPage,
			int numPerPage) throws Exception {
		return this.selectWhere(columns, null, 0, false, false, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, int orderType,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, 0, false, true, null, orderType,
				currentPage, numPerPage);
	}

	public String selectWhere(String[] columns, String[] values)
			throws Exception {
		return this.selectWhere(columns, values, 0, false, false, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNot(String[] columns, String[] values)
			throws Exception {
		return this.selectWhere(columns, values, 0, false, true, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhere(String[] columns, String[] values,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, 0, false, false, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, String[] values,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, 0, false, true, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhere(String[] columns) throws Exception {
		return this.selectWhere(columns, null, 0, false, false, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNot(String[] columns) throws Exception {
		return this.selectWhere(columns, null, 0, false, true, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhere(String[] columns, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, null, 0, false, false, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereNot(String[] columns, int currentPage,
			int numPerPage) throws Exception {
		return this.selectWhere(columns, null, 0, false, true, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType, String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, false,
				orderColumn, orderType, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType, String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, true,
				orderColumn, orderType, -1, -1);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType, String orderColumn, int orderType, int currentPage,
			int numPerPage) throws Exception {
		return this.selectWhere(columns, values, likeType, true, false,
				orderColumn, orderType, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType, String orderColumn, int orderType, int currentPage,
			int numPerPage) throws Exception {
		return this.selectWhere(columns, values, likeType, true, true,
				orderColumn, orderType, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, int likeType,
			String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, null, likeType, true, false,
				orderColumn, orderType, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, int likeType,
			String orderColumn, int orderType) throws Exception {
		return this.selectWhere(columns, null, likeType, true, true,
				orderColumn, orderType, -1, -1);
	}

	public String selectWhereLike(String[] columns, int likeType,
			String orderColumn, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, null, likeType, true, false,
				orderColumn, orderType, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, int likeType,
			String orderColumn, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, null, likeType, true, true,
				orderColumn, orderType, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType, int orderType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, false, null,
				orderType, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType, int orderType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, true, null,
				orderType, -1, -1);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, values, likeType, true, false, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType, int orderType, int currentPage, int numPerPage)
			throws Exception {
		return this.selectWhere(columns, values, likeType, true, true, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, int likeType, int orderType)
			throws Exception {
		return this.selectWhere(columns, null, likeType, true, false, null,
				orderType, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, int likeType,
			int orderType) throws Exception {
		return this.selectWhere(columns, null, likeType, true, true, null,
				orderType, -1, -1);
	}

	public String selectWhereLike(String[] columns, int likeType,
			int orderType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, likeType, true, false, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, int likeType,
			int orderType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, likeType, true, true, null,
				orderType, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, false, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType) throws Exception {
		return this.selectWhere(columns, values, likeType, true, true, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereLike(String[] columns, String[] values,
			int likeType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, likeType, true, false, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, String[] values,
			int likeType, int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, values, likeType, true, true, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns, int likeType)
			throws Exception {
		return this.selectWhere(columns, null, likeType, true, false, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNotLike(String[] columns, int likeType)
			throws Exception {
		return this.selectWhere(columns, null, likeType, true, true, null,
				OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereLike(String[] columns, int likeType,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, likeType, true, false, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereNotLike(String[] columns, int likeType,
			int currentPage, int numPerPage) throws Exception {
		return this.selectWhere(columns, null, likeType, true, true, null,
				OrderType.DESC_ORDER, currentPage, numPerPage);
	}

	public String selectWhereLike(String[] columns) throws Exception {
		return this.selectWhere(columns, null, LikeType.ALL_LIKE, true, false,
				null, OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNotLike(String[] columns) throws Exception {
		return this.selectWhere(columns, null, LikeType.ALL_LIKE, true, true,
				null, OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereLike(int currentPage, int numPerPage,
			String[] columns) throws Exception {
		return this.selectWhere(columns, null, LikeType.ALL_LIKE, true, false,
				null, OrderType.DESC_ORDER, -1, -1);
	}

	public String selectWhereNotLike(int currentPage, int numPerPage,
			String[] columns) throws Exception {
		return this.selectWhere(columns, null, LikeType.ALL_LIKE, true, true,
				null, OrderType.DESC_ORDER, -1, -1);
	}

	public String selectAll(String orderColumn, int oType) {
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		if (orderColumn == null) {
			if (ormBean == null) {
				orderColumn = "id";
			} else {
				for (Property p : ormBean.getProperty()) {
					if (("true".equals(p.getPk()) || "1".equals(p.getPk()))
							&& ("true".equals(p.getAutoIncrement()) || "1"
									.equals(p.getAutoIncrement()))) {
						orderColumn = p.getColumn();
						break;
					}
				}
			}
		}

		String orderType = OrderType.ASC_ORDER == oType ? "ASC" : "DESC";
		return String.format("SELECT * FROM %s ORDER BY %s %s ;", table,
				orderColumn, orderType);
	}

	public String selectAll(int oType) {
		return selectAll(null, oType);
	}

	public String selectAll() {
		return selectAll(null, OrderType.DESC_ORDER);
	}

	public String selectOne() throws Exception {
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(this.t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		// 反射工具
		ReflectUtil ru = new ReflectUtil(this.t);
		StringBuilder condition = new StringBuilder();
		if (ormBean == null) {
			String[] names = ru.getFieldsName();
			for (int i = 0; i < names.length; ++i) {
				String name = names[i];
				String and = i > 0 ? " AND " : "";
				if ("id".equals(name)) {
					condition.append(and).append(name).append(" = '");
					condition
							.append(
									ru
											.getMethod(
													"get"
															+ StringUtil
																	.toUpCaseFirst(name))
											.invoke(this.t)).append("'");
				}
			}
		} else {
			for (int i = 0; i < ormBean.getProperty().size(); ++i) {
				Property p = ormBean.getProperty().get(i);
				String and = i > 0 ? " AND " : "";
				if ("true".equals(p.getPk()) || "1".equals(p.getPk())) {
					condition
							.append(and)
							.append(p.getColumn())
							.append(" = '")
							.append(
									ru
											.getMethod(
													"get"
															+ StringUtil
																	.toUpCaseFirst(p
																			.getName()))
											.invoke(this.t)).append("'");
				}
			}
		}

		return String.format("SELECT * FROM %s WHERE %s ;", table, condition
				.toString());
	}

	public String nextOne() throws Exception {
		return this.nextOrPre(1, true);
	}

	public String nextOne(String column, String value) {
		return this.nextOrPre(column, value, 1, true);
	}

	public String preOne(String column, String value) {
		return this.nextOrPre(column, value, 1, false);
	}

	public String preOne() throws Exception {
		return this.nextOrPre(1, false);
	}

	public String nextOrPre(int num, boolean isNext) throws Exception {
		String idColumn = null;
		String type = isNext == true ? ">" : "<";
		String offset = null;
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		if (ormBean == null) {
			idColumn = "id";
		} else {
			for (int i = 0; i < ormBean.getProperty().size(); ++i) {
				Property p = ormBean.getProperty().get(i);
				if (("true".equals(p.getAutoIncrement()) || "1".equals(p
						.getAutoIncrement()))
						&& ("true".equals(p.getPk()) || "1".equals(p.getPk()))) {
					idColumn = p.getColumn();
					ReflectUtil ru = new ReflectUtil(t);
					offset = String.valueOf(ru.getMethod(
							"get" + StringUtil.toUpCaseFirst(p.getName()))
							.invoke(t));
					break;
				}
			}
		}
		return String.format("SELECT * FROM %s WHERE %s %s %s LIMIT %s ;",
				table, idColumn, type, offset, String.valueOf(num));
	}

	public String nextOrPre(String column, String value, int num, boolean isNext) {
		String type = isNext == true ? ">" : "<";
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		return String.format("SELECT * FROM %s WHERE %s %s %s LIMIT %s ;",
				table, column, type, value, String.valueOf(num));
	}

	/**
	 * 分页查询语句
	 * 
	 * @param currPage
	 *            当前查询页码
	 * @param numPerPage
	 *            每页显示记录条数
	 * @param orderColumn
	 *            对哪个字段排序
	 * @param oType
	 *            升序还是降序
	 * @return 字符串
	 */
	public String divPage(int currPage, int numPerPage, String orderColumn,
			int oType, String condition) {
		String sql = null;
		// 从缓存中取出配置信息
		ORMConfigBean ormBean = ORMConfigBeanCache.get(t.getClass());
		String table = ormBean == null ? t.getClass().getSimpleName() : ormBean
				.getTable();
		if (ormBean == null) {
			orderColumn = "id";
		} else {
			if (orderColumn == null) {
				for (Property p : ormBean.getProperty()) {
					if (("true".equals(p.getPk()) || "1".equals(p.getPk()))
							&& ("true".equals(p.getAutoIncrement()) || "1"
									.equals(p.getAutoIncrement()))) {
						orderColumn = p.getColumn();
						break;
					}
				}
			}
		}
		String orderType = OrderType.ASC_ORDER == oType ? "ASC" : "DESC";
		DAOConfigBean db = ((DAOConfigBean) SingleBeanCache
				.get(DAOConfigBean.class));
		String dbType = db == null ? "MYSQL" : db.getDataBaseType();
		if (DBType.MYSQL_DB.equalsIgnoreCase(dbType)) {
			sql = "SELECT * FROM ${table} ORDER BY ${orderColumn} ${orderType} LIMIT ${first}, ${numPerPage} ${condition} ;";
			sql = sql.replace("${first}", String.valueOf((currPage - 1)
					* numPerPage));
			sql = sql.replace("${numPerPage}", String.valueOf(numPerPage));
		} else if (DBType.MSSQL_DB.equalsIgnoreCase(dbType)) {
			sql = "SELECT * FROM ( SELECT TOP ${numPerPage} * FROM ( SELECT TOP ${last} * FROM ${table} ORDER BY ${orderColumn} ${orderType} ) AS aSysTable   ORDER BY ${orderColumn} DESC ) AS bSysTable   ORDER BY ${orderColumn} ASC ${condition} ;";
			sql = sql.replace("${numPerPage}", String.valueOf(numPerPage));
			sql = sql.replace("${last}", String.valueOf(numPerPage * currPage));
		}
		sql = sql.replace("${table}", table);
		sql = sql.replace("${orderColumn}", orderColumn);
		sql = sql.replace("${orderType}", orderType);
		if (condition != null) {
			sql = sql.replace("${condition}", " WHERE " + condition);
		} else {
			sql = sql.replace("${condition}", "");
		}

		return sql;
	}

	/**
	 * 分页查询 默认id排序
	 * 
	 * @param currPage
	 * @param numPerPage
	 * @param oType
	 * @return
	 */
	public String divPage(int currPage, int numPerPage, int oType) {
		return this.divPage(currPage, numPerPage, null, oType, null);
	}

	public String divPage(int currPage, int numPerPage, int oType,
			String condition) {
		return this.divPage(currPage, numPerPage, null, oType, condition);
	}

	/**
	 * 分页查询 默认id排序 且降序
	 * 
	 * @param currPage
	 * @param numPerPage
	 * @return
	 */
	public String divPage(int currPage, int numPerPage) {
		return this.divPage(currPage, numPerPage, null, OrderType.DESC_ORDER,
				null);
	}

	public String divPage(int currPage, int numPerPage, String condition) {
		return this.divPage(currPage, numPerPage, null, OrderType.DESC_ORDER,
				condition);
	}

	public T getT() {
		return t;
	}

	public void setT(T t) {
		this.t = t;
	}
}
